package com.htt.app.amnhac12h.sqlite;

import com.htt.app.amnhac12h.utils.Log;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class MySQLiteHelper extends SQLiteOpenHelper {
	
	public final String TAG = "MySQLiteHelper";
	
	// lock db
	public static String Lock = "dblock";
	
	// name database
	private static final String dbName = "qns.db";
	private static final int dbVersion = 1;
	
	// status database
	public static MySQLiteHelper myDBHelper = null;
	public static SQLiteDatabase myDB = null;
	
	// table Show
	public static final String showTable = "Show";
	
	public static final String showID = "showID";
	public static final String showName = "showName";
	public static final String showDes = "showDes";
	public static final String showIcon = "showIcon";
	public static final String showSource = "showSource";
	public static final String showOrder = "showOrder";
	public static final String showStatusFavourite = "showStatusFavourite";
	
	// database create table Show
	private final String DB_CREATE_TABLE_SHOW = "CREATE TABLE "
			+ showTable + "(" + showID + " INTEGER,"
			+ showName + " TEXT," + showDes + " TEXT,"
			+ showIcon + " TEXT," + showSource + " TEXT," 
			+ showOrder + " INTEGER," 
			+ showStatusFavourite + " INTEGER);";
		
	public MySQLiteHelper(Context context) {
		super(context, dbName, null, dbVersion);
		Log.w(TAG, "create database version " + dbVersion);
	}
	
	
	@Override
	public void onCreate(SQLiteDatabase db) {
		// TODO Auto-generated method stub
		Log.w(TAG, "create tables in database");
		
		db.execSQL(DB_CREATE_TABLE_SHOW);
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		// TODO Auto-generated method stub
		Log.w(TAG, "Upgrading database from version " + oldVersion + " to "
                + newVersion + ", which will destroy all old data");
		 // Drop older table if existed
        db.execSQL("DROP TABLE IF EXISTS " + showTable);
        // Create tables again
        onCreate(db);
	}
	
}
